package com.gl.controller.system;

import com.gl.pojo.Result;
import com.gl.pojo.entity.UserCount;
import com.gl.pojo.vo.ActiveUserVo;
import com.gl.pojo.vo.MeetingCountVo;
import com.gl.pojo.vo.MetricsVo;
import com.gl.service.MeetingService;
import com.gl.service.MetricsService;
import com.gl.service.UserCountService;
import com.gl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/system")
public class SystemController {
    @Autowired
    private UserCountService userCountService;
    @Autowired
    private MetricsService metricsService;
    @Autowired
    private MeetingService meetingService;
    @Autowired
    private UserService userService;

    @GetMapping("/activity")
    public Result getUserCount(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,
                               @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        List<UserCount> userCounts = userCountService.getUserCount(start, end);
        return Result.success(userCounts);
    }

    @GetMapping("/metrics")
    public Result getMetrics(){
        MetricsVo metricsVo = metricsService.getMetricsVo();
        return Result.success(metricsVo);
    }

    /**
     * 获取会议每日创建数量
     * @return
     */
    @GetMapping("/meeting")
    public Result getMeetingCount(LocalDate start, LocalDate end) {
        List<MeetingCountVo> result = meetingService.countByTime(start, end);
        return Result.success(result);
    }

    /**
     * 获取活跃用户数量，在一星期内登录就属于活跃用户
     */
    @GetMapping("/activeUser")
    public Result getActiveUserCount() {
        Integer activeUserCount = userService.getActiveUserCount();
        Integer inactiveUserCount = userService.count() - activeUserCount;
        ActiveUserVo activeUserVo = new ActiveUserVo();
        activeUserVo.setActive(activeUserCount);
        activeUserVo.setInactive(inactiveUserCount);
        return Result.success(activeUserVo);
    }


}
